// import axios from 'axios'
// import { Message } from 'element-ui'
// import router from 'vue-router'
// const http = axios.create({
//   baseURL: 'http://www.ysqorz.top:8888/api/private/v1',
//   timeout: 5000
// })
// http.interceptors.request.use(
//   (config) => {
//     if (config.url !== '/login') {
//       const token = sessionStorage.getItem('token')
//       token && (config.headers.Authorization = token)
//     }
//     return config
//   },
//   (error) => {
//     return Promise.reject(error)
//   }
// )
// http.interceptors.response.use(
//   (res) => {
//     const {
//       meta: { state, msg },
//       data
//     } = res.data
//     const successMsg = [200, 201, 202, 204]
//     if (successMsg.includes(state)) {
//       Message({
//         type: 'success',
//         message: msg
//       })
//       return data
//     }
//     Message({
//       type: 'error',
//       message: msg
//     })
//     if (msg == '无效token') {
//       router.push('/login')
//     }
//     return Promise.reject(msg)
//   },
//   (error) => {
//     return Promise.reject(error)
//   }
// )
// export default http

import axios from 'axios'
import { Message } from 'element-ui'
import router from 'vue-router'
const http = axios.create({
  baseURL: 'http://www.ysqorz.top:8888/api/private/v1',
  timeout: 5000
})
http.interceptors.request.use(
  (config) => {
    if (config.url !== '/login') {
      const token = sessionStorage.getItem('token')
      token && (config.headers.Authorization = token)
    }
    return config
  },
  (error) => {
    return Promise.reject(error)
  }
)
http.interceptors.response.use(
  (res) => {
    const {
      meta: { msg, status },
      data
    } = res.data
    const Arr = [200, 201, 202, 204]
    if (Arr.includes(status)) {
      Message({
        type: 'success',
        Message: msg
      })
      return data
    }
    Message({
      type: 'error',
      Message: msg
    })
    if (msg == '无效token') {
      router.push('/login')
    }
    return Promise.reject(msg)
  },
  (error) => {
    return Promise.reject(error)
  }
)
export default http





import axios from 'axios'
import {Message} from 'element-ui'
import router from 'vue-router'
const http=axios.create({
    timeout:5000,
    baseURL:'http://www.ysqorz.top:8888/api/private/v1'
})
http.interceptors.request.use(config=>{
    if(config.url!=='/login'){
        const token=sessionStorage.getItem('token')
        token&&(config.headers.Authorization=token )
    }
    return config
},(error)=>{
    return Promise.reject(error)
})
http.interceptors.response.use(res=>{
    const {data,meta:{msg,status}}=res.data
    const Arr=[200,201,204]
    if(Arr.includes(status)){
        Message({
            type:'success',
            Message:msg
        })
        return data
    }
    Message({
        type:'error',
        Message:msg
    })
    if(mag==='无效token'){
        router.push('/login')
    }
    return Promise.reject(msg)
},(error)=>{
    return Promise.reject(error)
})
export default http




import axios from 'axios'
import {Message} from 'element-ui'
import router from 'vue-router'
const http=axios.create({
    baseURL:'http://www.ysqorz.top:8888/api/private/v1',
    timeout:5000
})
http.interceptors.request.use(config=>{
    if(connfig.url!=='/login'){
        const token=sessionStorage.getItem('token')
        token&&(connfig.headers.Authorization='token')
    }
    return connfig
},(error)=>{
    return Promise.reject(error)
})
http.interceptors.response.use(res=>{
    const {data,meta:{msg,status}}=res.data
    const Arr=[200,201,202,204]
    if(Arr.includes(status)){
        Message({
            type:'success',
            Message:msg
        })
        return data
    }
    Message({
        type:'error',
        Message:msg
    })
    if(msg === '无效token'){
        router.push('/login')
    }
    return Promise.reject(msg)
},(error)=>{
    return Promise.reject(error)
})
export default http
